# Copyright (c) 2008, Eamonn Faherty
# This is licensed under the MIT licence.

import unittest,sys,os
sys.path.append( os.path.abspath('../') )

from checkstyleas3 import asCheckStyle
from checkstyleas3 import asModel

import asBuilder, asCheckStyle


class ASCheckStyleTestCaseForInterface(unittest.TestCase):
	def testCheckInterfaceIsTypeFail(self):
		"Check that InterfaceIsType gives a negative"
		interface = asModel.ASClass();
		interface.isInterface = True
		check = asCheckStyle.CheckInterface()
		self.assertEqual(-1,check.checkInterfaceIsType(interface))

	def testCheckInterfaceIsTypePass(self):
		"Check that InterfaceIsType gives a positive"
		interface = asModel.ASClass()
		interface.isInterface = True
		interface.methods = [asModel.ASMethod("foo","String"), asModel.ASMethod("bar","String")]
		check = asCheckStyle.CheckInterface()
		self.assertEqual(0,check.checkInterfaceIsType(interface))

class ASCheckStyleTestCaseForPackage(unittest.TestCase):
	def testCheckAvoidStarImportPass(self):
		"Check that AvoidStarImportPass gives a positive"
		package = asModel.ASPackage()
		package.imports = ["uk.co.doughball.ui.Button"]
		check = asCheckStyle.CheckPackage()
		self.assertEqual(0, check.checkAvoidStarImport(package))

	def testCheckAvoidStarImportFail(self):
		"Check that AvoidStarImportPass gives a negative"
		package = asModel.ASPackage()
		package.imports = ["uk.co.doughball.ui.*"]
		check = asCheckStyle.CheckPackage()
		self.assertEqual(-1, check.checkAvoidStarImport(package))

class ASCheckStyleTestCaseForMethod(unittest.TestCase):
	def testCheckParameterNumberPass(self):
		"Check that CheckParameterNumberPass gives a positive"
		method = asModel.ASMethod();
		type = asModel.ASType("bar","Bar")
		var = asModel.ASVariable('foo',type)
		method.arguments = {'foo':var}
		check = asCheckStyle.CheckMethod()
		self.assertEqual(0, check.checkParameterNumber(method))

	def testCheckParameterNumberFail(self):
		"Check that CheckParameterNumberPass gives a negative"
		method = asModel.ASMethod();
		type = asModel.ASType("bar","Bar")
		var = asModel.ASVariable('foo',type)
		method.arguments = {'foo':var, 'bar':var, 'oo':var, 'hello':var, 'world':var, 'arghh':var , 'fub':var , 'baar':var }
		check = asCheckStyle.CheckMethod()
		self.assertEqual(-1, check.checkParameterNumber(method))

if __name__ == "__main__":
	unittest.main()